package team.knowers.qzh.qzhserver.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.qzh.qzhserver.common.convention.result.Result;
import team.knowers.qzh.qzhserver.common.convention.result.Results;
import team.knowers.qzh.qzhserver.common.database.BaseDO;
import team.knowers.qzh.qzhserver.dao.entity.CourseDO;
import team.knowers.qzh.qzhserver.dto.resp.CourseDetailsRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.CourseSimpleRespDTO;
import team.knowers.qzh.qzhserver.service.CourseService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xtg
 */
@RestController
@RequiredArgsConstructor
public class CourseController {
    private final CourseService courseService;

    /**
     * 根据课程id获得课程详情信息
     */
    @GetMapping("/api/qzh-server/admin/v1/course/details/{courseId}")
    public Result<CourseDetailsRespDTO> getCourseDetailsById(@PathVariable("courseId") Long id) {
        return Results.success(courseService.getCourseDetailsById(id));
    }

    /**
     * 根据课程id获得课程评分
     */
    @GetMapping("/api/qzh-server/admin/v1/course/mark/{courseId}")
    public Result<String> getMarkById(@PathVariable("courseId") Long id) {
        return Results.success(courseService.getMarkById(id));
    }

    /**
     * 用户最近课程发布
     */
    @GetMapping("/api/qzh-server/admin/v1/course/recent")
    public Result<List<CourseSimpleRespDTO>> homeUserCourseByTimeDesc(@RequestParam("userId") Long userId) {
        return Results.success(courseService.homeUserCourseByTimeDesc(userId));
    }
}
